﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PBOffice.Models;
namespace PBOffice.DAL
{
    public class OverWorkService
    {
        public void AddOverWork(OverWork over)
        {
            string sql = "insert [OverWork] (StfCode,Hours,BeginDate,EndDate,Memo,StatusId) values(@StfCode,@Hours,@BeginDate,"
            + "@EndDate,@Memo,@StatusId)";
            SqlParameter[] spa = {
                                   new SqlParameter("@StfCode",over.StfCode),
                                  new SqlParameter("@Hours",over.Hours),
                                   new SqlParameter("@BeginDate",over.BeginDate),
                                   new SqlParameter("@EndDate",over.EndDate),
                                   new SqlParameter("@Memo",over.Memo),
                                   new SqlParameter("@StatusId",over.Status.StatusId)
                               };
            SqlHelp.ExecuteNonQuery(SqlHelp.connectionstring, CommandType.Text, sql, spa);
        }
        public List<OverWork> GetOverWorkByNameAndMonth(string num, string name)
        {
            List<OverWork> list = new List<OverWork>();
            SqlParameter[] spa = {
                                     new SqlParameter("@StfName",name),
                                     new SqlParameter("@Num",num)
                                 };
            using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, "proc_StfNameNumOver", spa))
            {
                while (dr.Read())
                {
                    OverWork over = new OverWork();
                    over.Hours =Convert.ToDouble(dr["Hours"]);
                    over.StfCode = dr["StfCode"].ToString();
                    list.Add(over);
                }
            }
            return list;
        }
    }
}
